package net.ib.mtalk.ui.buddy.info;

import net.ib.mntalk.protocol.Session.AddBlockUsersReq;
import net.ib.mntalk.protocol.Session.GetUserAccessControlReq;
import net.ib.mntalk.protocol.Session.SetBuddyInfoReq;
import net.ib.mtalk.constant.MTalkConstant;
import net.ib.mtalk.database.task.InsertFavoriteTask;
import net.ib.mtalk.database.task.RemoveFavoriteTask;
import net.ib.mtalk.network.task.GetUserAccessControlTask;
import net.ib.mtalk.network.task.SetBlockBuddyTask;
import net.ib.mtalk.network.task.SetRemoveBuddyTask;
import net.ib.mtalk.ui.UIController;
import net.ib.mtalk.util.GpbSupport;
import net.ib.mtalk.util.MTalkLogWriter;
import android.content.Context;
import android.os.Handler;
import android.util.Log;

public class BuddyInfoController extends UIController {
	
	private Handler mUiHandler = new Handler();

	public BuddyInfoController(Context context, Handler handler) {
		super(context, handler);
		mUiHandler = handler;
	}

	public void buddyInfoDetail() {
		try{
			MTalkLogWriter.d("BuddyInfoController.buddyInfoDetail()");
//			AllAddContactsTask task = new AllAddContactsTask(mContext, mUiHandler);
//			task.execute();
		} catch(Exception e) {
			Log.e(MTalkConstant.TAG, "buddyInfoDetail", e);
		}
	}

	public void isFavorite() {
		try{
			MTalkLogWriter.d("BuddyInfoController.isFavorite()");
//			Cursor cursor = mContext.getContentResolver().query(BuddyTable.CONTENT_URI, BuddyTable.PROJECTION, selection, selectionArgs, sortOrder)
//			AllAddContactsTask task = new AllAddContactsTask(mContext, mUiHandler);
//			task.execute();
		} catch(Exception e) {
			Log.e(MTalkConstant.TAG, "isFavorite", e);
		}
	}

	public void insertFavorite(String msb, String lsb) {
		try{
			MTalkLogWriter.d("BuddyInfoController.insertFavorite()");
			InsertFavoriteTask task = new InsertFavoriteTask(mContext, mUiHandler, GpbSupport.makeUuidMsg(Long.parseLong(msb), Long.parseLong(lsb)));
			task.execute();
		} catch(Exception e) {
			Log.e(MTalkConstant.TAG, "insertFavorite", e);
		}
	}

	public void removeFavorite(String msb, String lsb) {
		try{
			MTalkLogWriter.d("BuddyInfoController.removeFavorite()");
			RemoveFavoriteTask task = new RemoveFavoriteTask(mContext, mUiHandler, GpbSupport.makeUuidMsg(Long.parseLong(msb), Long.parseLong(lsb)));
			task.execute();
		} catch(Exception e) {
			Log.e(MTalkConstant.TAG, "removeFavorite", e);
		}
	}

	public void blockBuddy(SetBuddyInfoReq setBuddyInfoReq) {
		try{
			MTalkLogWriter.d("BuddyInfoController.blockBuddy()");
			SetBlockBuddyTask task = new SetBlockBuddyTask(mContext, mUiHandler, setBuddyInfoReq);
			task.execute();
		} catch(Exception e) {
			Log.e(MTalkConstant.TAG, "blockBuddy", e);
		}
	}

	public void removeBuddy(SetBuddyInfoReq setBuddyInfoReq) {
		try{
			MTalkLogWriter.d("BuddyInfoController.removeBuddy()");
			SetRemoveBuddyTask task = new SetRemoveBuddyTask(mContext, mUiHandler, setBuddyInfoReq);
			task.execute();
		} catch(Exception e) {
			Log.e(MTalkConstant.TAG, "removeBuddy", e);
		}
	}

	public void getAccessControl(GetUserAccessControlReq getUserAccessControlReq) {
		try{
			MTalkLogWriter.d("BuddyInfoController.getAccessControl()");
			GetUserAccessControlTask task = new GetUserAccessControlTask(mContext, mUiHandler, getUserAccessControlReq);
			task.execute();
		} catch(Exception e) {
			Log.e(MTalkConstant.TAG, "getAccessControl", e);
		}
	}
}
